home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue71 / Clinic / RTTIEgU.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2001-05-08  |  2.5 KB  |  113 lines

  1. unit RTTIEgU;
  2.  
  3. {$ifdef Ver80} { Delphi 1.0x }
  4.   {$define DelphiLessThan5}
  5. {$endif}
  6. {$ifdef Ver90} { Delphi 2.0x }
  7.   {$define DelphiLessThan5}
  8. {$endif}
  9. {$ifdef Ver93} { C++ Builder 1.0x }
  10.   {$define DelphiLessThan5}
  11. {$endif}
  12. {$ifdef Ver100} { Delphi 3.0x }
  13.   {$define DelphiLessThan5}
  14. {$endif}
  15. {$ifdef Ver110} { C++ Builder 3.0x }
  16.   {$define DelphiLessThan5}
  17. {$endif}
  18. {$ifdef Ver120} { Delphi 4.0x }
  19.   {$define DelphiLessThan5}
  20. {$endif}
  21. {$ifdef Ver125} { C++Builder 4.0x }
  22.   {$define DelphiLessThan5}
  23. {$endif}
  24.  
  25. interface
  26.  
  27. uses
  28.   WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  29.   StdCtrls;
  30.  
  31. type
  32.   TForm1 = class(TForm)
  33.     ListBox1: TListBox;
  34.     Button1: TButton;
  35.     Label1: TLabel;
  36.     Edit1: TEdit;
  37.     RadioButton1: TRadioButton;
  38.     CheckBox1: TCheckBox;
  39.     Button2: TButton;
  40.     procedure Button1Click(Sender: TObject);
  41.     procedure Button2Click(Sender: TObject);
  42.     procedure FormCreate(Sender: TObject);
  43.   private
  44.     { Private declarations }
  45.   public
  46.     { Public declarations }
  47.   end;
  48.  
  49. var
  50.   Form1: TForm1;
  51.  
  52. implementation
  53.  
  54. {$R *.DFM}
  55.  
  56. uses
  57.   Typinfo;
  58.  
  59. procedure TForm1.Button1Click(Sender: TObject);
  60. {$ifndef DelphiLessThan5}
  61. const
  62.   PropName = 'Caption';
  63.   Default = -1;
  64. var
  65.   Loop, CaptionVal: Integer;
  66.   Comp: TComponent;
  67. {$endif}
  68. begin
  69. {$ifndef DelphiLessThan5}
  70.   for Loop := 0 to ComponentCount - 1 do
  71.   begin
  72.     Comp := Components[Loop];
  73.     if IsPublishedProp(Comp, PropName) then
  74.     begin
  75.       CaptionVal := StrToIntDef(GetStrProp(Comp, PropName), Default);
  76.       if CaptionVal <> Default then
  77.         ListBox1.Items.Add(Format(
  78.           'The %s component %s has a numeric caption: %d',
  79.           [Comp.ClassName, Comp.Name, CaptionVal]))
  80.     end
  81.   end
  82. {$endif}
  83. end;
  84.  
  85. procedure TForm1.Button2Click(Sender: TObject);
  86. const
  87.   PropName = 'Caption';
  88.   Default = -1;
  89. var
  90.   Loop, CaptionVal: Integer;
  91.   Comp: TComponent;
  92.   PropInfo: PPropInfo;
  93. begin
  94.   for Loop := 0 to ComponentCount - 1 do
  95.   begin
  96.     Comp := Components[Loop];
  97.     PropInfo := GetPropInfo(Comp.ClassInfo, PropName);
  98.     if Assigned(PropInfo) then
  99.     begin
  100.       CaptionVal := StrToIntDef(GetStrProp(Comp, PropInfo), Default);
  101.       if CaptionVal <> Default then
  102.         ListBox1.Items.Add(Format('The %s component %s has a numeric caption: %d', [Comp.ClassName, Comp.Name, CaptionVal]))
  103.     end
  104.   end
  105. end;
  106.  
  107. procedure TForm1.FormCreate(Sender: TObject);
  108. begin
  109.   SendMessage(ListBox1.Handle, LB_SETHORIZONTALEXTENT, 800, 0)
  110. end;
  111.  
  112. end.
  113.